Load libraries (packages)

library("respR") ## respirometry/slope analysis
library("tidyverse") ## data manipulation

Set working directory

setwd("[PATH TO DIRECTORY]")

System1 - Dell

Importing data from firesting for resting

preexperiment_date <- "29 June 2023 10 26AM/All"
postexperiment_date <- "29 June 2023 03 23PM/All"

##--- last fish run in trial ---##
experiment_date <- "29 June 2023 12 12PM/Oxygen"
experiment_date2 <- "29 June 2023 12 12PM/All"

firesting <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19)

Cycle_1 <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Cycle_last <-read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_date2,"slopes/Cycle_21.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

System2 - Asus

Importing data from firesting for resting

preexperiment_date_asus <- "29 June 2023 10 49AM/All"
postexperiment_date_asus <- "29 June 2023 04 56PM/All"

##--- last fish run in trial ---##
experiment_date_asus <- "29 June 2023 01 08PM/Oxygen"
experiment_date2_asus <- "29 June 2023 01 08PM/All"

firesting_asus <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19)

Cycle_1_asus <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Cycle_last_asus <-read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date2_asus,"slopes/Cycle_21.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Chamber volumes

chamber1_dell = 0.04650#+0.00022
chamber2_dell = 0.04593#+0.00022
chamber3_dell = 0.04977#+0.00022
chamber4_dell = 0.04860#+0.00022

chamber1_asus = 0.04565
chamber2_asus = 0.04573#+0.00385
chamber3_asus = 0.04551#+0.00322
chamber4_asus = 0.04791#+0.00277

Date_tested="2023-06-29"
Clutch = "131" 
Male = "CPRE447" 
Female = "CPRE452"
Population = "Pretty patches"
Tank =152 
salinity =37 
Date_analysed = Sys.Date() 

Replicates

1

Enter specimen data

Replicate = 1 
mass = 0.0004318
chamber = "ch4" 
Swim = "good/good"
chamber_vol = chamber4_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "29 June 2023 11 43AM/Oxygen"
experiment_mmr_date2 <- "29 June 2023 11 43AM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.00110541

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.0006413093

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  8  9 10 11 12 13 14 15 18 19 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 8.57
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  3  4  5  6 20 22 47 48 50 51 53 54 55 56 61 62 71 72 74 75
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.95 8.57
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 3 rate(s) removed, 18 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 12 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density   row endrow     time
## 1:  10    1     266.6172 -0.01464672 0.963      NA  4876   5131 11310.35
## 2:  14    1     287.9925 -0.01392057 0.966      NA  7036   7286 13470.35
## 3:  15    1     283.4811 -0.01303876 0.983      NA  7542   7795 14010.80
## 4:  19    1     339.9426 -0.01479215 0.964      NA  9694   9949 16170.46
## 5:  20    1     366.4635 -0.01589229 0.980      NA 10234  10489 16710.46
## 6:  21    1     369.0801 -0.01554835 0.989      NA 10774  11029 17250.46
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1: 11565.35 100.47 96.779 -0.01464672  3.143711e-04   -0.01496109 -0.01496109
## 2: 13725.16 100.59 97.116 -0.01392057 -2.680703e-05   -0.01389376 -0.01389376
## 3: 14265.87 100.58 97.245 -0.01303876 -1.121969e-04   -0.01292656 -0.01292656
## 4: 16425.46 100.37 96.595 -0.01479215 -4.533309e-04   -0.01433882 -0.01433882
## 5: 16965.46 100.53 96.483 -0.01589229 -5.386292e-04   -0.01535366 -0.01535366
## 6: 17505.46 100.56 96.792 -0.01554835 -6.239275e-04   -0.01492442 -0.01492442
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0486 0.0004318   NA 37 30 1.013253 -0.1610103
## 2:     %Air       sec 0.0486 0.0004318   NA 37 30 1.013253 -0.1495238
## 3:     %Air       sec 0.0486 0.0004318   NA 37 30 1.013253 -0.1391148
## 4:     %Air       sec 0.0486 0.0004318   NA 37 30 1.013253 -0.1543134
## 5:     %Air       sec 0.0486 0.0004318   NA 37 30 1.013253 -0.1652351
## 6:     %Air       sec 0.0486 0.0004318   NA 37 30 1.013253 -0.1606156
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -372.8818          NA  mgO2/hr/kg   -372.8818
## 2:   -346.2802          NA  mgO2/hr/kg   -346.2802
## 3:   -322.1743          NA  mgO2/hr/kg   -322.1743
## 4:   -357.3724          NA  mgO2/hr/kg   -357.3724
## 5:   -382.6659          NA  mgO2/hr/kg   -382.6659
## 6:   -371.9677          NA  mgO2/hr/kg   -371.9677
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
131 1 CPRE447 CPRE452 Pretty patches 152 0.0004318 ch4 Dell 0.0486 2023-06-29 2024-08-16 good/good 37 30 366.2336 0.1581397 0.9724

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  8  9 10 11 12 13 14 15 18 19 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 1.35
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1] 15 16 23 24 34 35 41 42 45 47 48 49 50 51 57 58 75 76 81 82
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.95 1.08
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     354.6940 -0.05393352 0.9958415      NA    27     87
##   2:    NA     2     354.4349 -0.05387930 0.9957958      NA    26     86
##   3:    NA     3     354.3406 -0.05385955 0.9959755      NA    24     84
##   4:    NA     4     354.3147 -0.05385368 0.9959872      NA    28     88
##   5:    NA     5     354.2864 -0.05384823 0.9959764      NA    25     85
##  ---                                                                    
## 237:    NA   237     220.7518 -0.02616230 0.9639190      NA   129    189
## 238:    NA   238     220.3942 -0.02608990 0.9642217      NA   132    192
## 239:    NA   239     220.2687 -0.02606341 0.9642537      NA   130    190
## 240:    NA   240     220.1843 -0.02604644 0.9642938      NA   131    191
## 241:    NA   241     220.0655 -0.02602274 0.9643926      NA   133    193
##         time endtime    oxy endoxy        rate
##        <num>   <num>  <num>  <num>       <num>
##   1: 4730.38 4790.38 99.522 96.346 -0.05393352
##   2: 4729.42 4789.42 99.623 96.395 -0.05387930
##   3: 4727.35 4787.35 99.740 96.439 -0.05385955
##   4: 4731.35 4791.35 99.468 96.330 -0.05385368
##   5: 4728.35 4788.35 99.642 96.436 -0.05384823
##  ---                                          
## 237: 4832.35 4892.35 94.422 92.726 -0.02616230
## 238: 4835.35 4895.35 94.317 92.615 -0.02608990
## 239: 4833.35 4893.35 94.355 92.694 -0.02606341
## 240: 4834.35 4894.35 94.301 92.654 -0.02604644
## 241: 4836.35 4896.35 94.170 92.612 -0.02602274
## 
## Regressions : 241 | Results : 241 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 241 adjusted rate(s):
## Rate          : -0.05393352
## Adjustment    : 0.00110541
## Adjusted Rate : -0.05503893 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 241 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 240 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1      354.694 -0.05393352 0.9958415      NA  27     87 4730.38
##    endtime    oxy endoxy        rate adjustment rate.adjusted  rate.input
## 1: 4790.38 99.522 96.346 -0.05393352 0.00110541   -0.05503893 -0.05503893
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0486 0.0004318   NA 37 30 1.013253 -0.5923254
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1371.759          NA  mgO2/hr/kg   -1371.759
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
131 1 CPRE447 CPRE452 Pretty patches 152 0.0004318 ch4 Dell 0.0486 2023-06-29 2024-08-16 good/good 37 30 366.2336 0.1581397 0.9724 1371.759 0.5923254 0.9958415 1005.525 0.4341857

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 350 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

2

Enter specimen data

Replicate = 2 
mass = 0.0006713 
chamber = "ch3" 
Swim = "good/good"
chamber_vol = chamber3_dell
system1 = "Dell7440"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "29 June 2023 12 01PM/Oxygen"
experiment_mmr_date2 <- "29 June 2023 12 01PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.001431895

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post
## [1] -0.0007111568

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  8  9 10 11 12 13 14 15 18 19 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 8.57
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME)
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  3  4  5  6 20 22 47 48 50 51 53 54 55 56 61 62 71 72 74 75
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.95 8.57
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 3 rate(s) removed, 18 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 12 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density   row endrow     time
## 1:  10    1     268.9655 -0.01484514 0.982      NA  4876   5131 11310.35
## 2:  11    1     305.3973 -0.01719899 0.955      NA  5416   5671 11850.35
## 3:  13    1     318.7770 -0.01687659 0.993      NA  6496   6751 12930.35
## 4:  16    1     347.5976 -0.01693584 0.965      NA  8076   8329 14550.60
## 5:  18    1     329.9610 -0.01463624 0.975      NA  9154   9409 15630.46
## 6:  20    1     329.4214 -0.01365596 0.955      NA 10234  10489 16710.46
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1: 11565.35 100.65 96.979 -0.01484514  0.0004613687   -0.01530651 -0.01530651
## 2: 12105.36 100.92 96.846 -0.01719899  0.0003567152   -0.01755570 -0.01755570
## 3: 13185.35 100.31 96.046 -0.01687659  0.0001474110   -0.01702400 -0.01702400
## 4: 14805.46 100.73 96.281 -0.01693584 -0.0001665816   -0.01676926 -0.01676926
## 5: 15885.46 100.89 97.245 -0.01463624 -0.0003758732   -0.01426037 -0.01426037
## 6: 16965.46 100.84 97.508 -0.01365596 -0.0005851783   -0.01307078 -0.01307078
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04977 0.0006713   NA 37 30 1.013253 -0.1686933
## 2:     %Air       sec 0.04977 0.0006713   NA 37 30 1.013253 -0.1934817
## 3:     %Air       sec 0.04977 0.0006713   NA 37 30 1.013253 -0.1876218
## 4:     %Air       sec 0.04977 0.0006713   NA 37 30 1.013253 -0.1848143
## 5:     %Air       sec 0.04977 0.0006713   NA 37 30 1.013253 -0.1571638
## 6:     %Air       sec 0.04977 0.0006713   NA 37 30 1.013253 -0.1440533
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -251.2935          NA  mgO2/hr/kg   -251.2935
## 2:   -288.2195          NA  mgO2/hr/kg   -288.2195
## 3:   -279.4902          NA  mgO2/hr/kg   -279.4902
## 4:   -275.3081          NA  mgO2/hr/kg   -275.3081
## 5:   -234.1186          NA  mgO2/hr/kg   -234.1186
## 6:   -214.5885          NA  mgO2/hr/kg   -214.5885
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
131 2 CPRE447 CPRE452 Pretty patches 152 0.0006713 ch3 Dell7440 0.04977 2023-06-29 2024-08-16 good/good 37 30 265.686 0.178355 0.974

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  8  9 10 11 12 13 14 15 18 19 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 1.35
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row,  
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  8 10 14 15 18 19 32 33 34 35 37 38 70 71
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.96 1.12
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     383.8782 -0.04879716 0.9925113      NA   180    240
##   2:    NA     2     383.6389 -0.04875772 0.9927326      NA   179    239
##   3:    NA     3     383.2800 -0.04869728 0.9927604      NA   181    241
##   4:    NA     4     382.8682 -0.04862910 0.9928051      NA   184    244
##   5:    NA     5     382.6918 -0.04859973 0.9927924      NA   183    243
##  ---                                                                    
## 237:    NA   237     301.5358 -0.03514008 0.9856579      NA   237    297
## 238:    NA   238     301.3851 -0.03511459 0.9861090      NA   240    300
## 239:    NA   239     301.3588 -0.03511068 0.9861228      NA   241    301
## 240:    NA   240     300.9969 -0.03505095 0.9849922      NA   238    298
## 241:    NA   241     300.7900 -0.03501674 0.9856623      NA   239    299
##         time endtime    oxy endoxy        rate
##        <num>   <num>  <num>  <num>       <num>
##   1: 5968.38 6028.38 92.648 89.780 -0.04879716
##   2: 5967.36 6027.36 92.583 89.631 -0.04875772
##   3: 5969.35 6029.35 92.618 89.726 -0.04869728
##   4: 5972.35 6032.35 92.520 89.517 -0.04862910
##   5: 5971.35 6031.35 92.472 89.496 -0.04859973
##  ---                                          
## 237: 6025.35 6085.35 89.857 87.741 -0.03514008
## 238: 6028.35 6088.35 89.780 87.638 -0.03511459
## 239: 6029.35 6089.35 89.726 87.481 -0.03511068
## 240: 6026.36 6086.36 89.715 87.715 -0.03505095
## 241: 6027.35 6087.35 89.631 87.651 -0.03501674
## 
## Regressions : 241 | Results : 241 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 241 adjusted rate(s):
## Rate          : -0.04879716
## Adjustment    : 0.001431895
## Adjusted Rate : -0.05022905 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 241 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 240 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     383.8782 -0.04879716 0.9925113      NA 180    240 5968.38
##    endtime    oxy endoxy        rate  adjustment rate.adjusted  rate.input
## 1: 6028.38 92.648  89.78 -0.04879716 0.001431895   -0.05022905 -0.05022905
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04977 0.0006713   NA 37 30 1.013253 -0.5535754
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -824.6319          NA  mgO2/hr/kg   -824.6319
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
131 2 CPRE447 CPRE452 Pretty patches 152 0.0006713 ch3 Dell7440 0.04977 2023-06-29 2024-08-16 good/good 37 30 265.686 0.178355 0.974 824.6319 0.5535754 0.9925113 558.9459 0.3752204

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 351 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

3

Enter specimen data

Replicate = 3 
mass = 0.0005840 
chamber = "ch2" 
Swim = "good/good"
chamber_vol = chamber2_dell
system1 = "Dell7440"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "29 June 2023 12 01PM/Oxygen"
experiment_mmr_date2 <- "29 June 2023 12 01PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.001374391

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post
## [1] -0.001942909

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  8  9 10 11 12 13 14 15 18 19 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 8.57
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME)
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  3  4  5  6 20 22 47 48 50 51 53 54 55 56 61 62 71 72 74 75
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.95 8.57
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 1 rate(s) removed, 20 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 14 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   3    1     227.4645 -0.01670619 0.985      NA 1126   1381  7560.35
## 2:  14    1     363.5929 -0.01939631 0.968      NA 7066   7316 13500.35
## 3:  15    1     377.3485 -0.01961507 0.980      NA 7572   7825 14040.81
## 4:  17    1     389.5378 -0.01903491 0.988      NA 8644   8899 15120.46
## 5:  18    1     359.6130 -0.01647768 0.972      NA 9184   9439 15660.46
## 6:  19    1     439.5438 -0.02085810 0.986      NA 9724   9979 16200.46
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1:  7815.35 100.90 96.543 -0.01670619  0.0009970478   -0.01770324 -0.01770324
## 2: 13755.16 101.19 96.099 -0.01939631 -0.0007848703   -0.01861144 -0.01861144
## 3: 14295.87 101.60 97.050 -0.01961507 -0.0009470410   -0.01866803 -0.01866803
## 4: 15375.46 101.59 96.443 -0.01903491 -0.0012709173   -0.01776399 -0.01776399
## 5: 15915.46 101.62 97.500 -0.01647768 -0.0014329124   -0.01504477 -0.01504477
## 6: 16455.46 101.28 95.922 -0.02085810 -0.0015949076   -0.01926319 -0.01926319
##    oxy.unit time.unit  volume     mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04593 0.000584   NA 37 30 1.013253 -0.1800542
## 2:     %Air       sec 0.04593 0.000584   NA 37 30 1.013253 -0.1892912
## 3:     %Air       sec 0.04593 0.000584   NA 37 30 1.013253 -0.1898668
## 4:     %Air       sec 0.04593 0.000584   NA 37 30 1.013253 -0.1806721
## 5:     %Air       sec 0.04593 0.000584   NA 37 30 1.013253 -0.1530157
## 6:     %Air       sec 0.04593 0.000584   NA 37 30 1.013253 -0.1959200
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -308.3121          NA  mgO2/hr/kg   -308.3121
## 2:   -324.1288          NA  mgO2/hr/kg   -324.1288
## 3:   -325.1144          NA  mgO2/hr/kg   -325.1144
## 4:   -309.3700          NA  mgO2/hr/kg   -309.3700
## 5:   -262.0132          NA  mgO2/hr/kg   -262.0132
## 6:   -335.4795          NA  mgO2/hr/kg   -335.4795
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple")  
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
131 3 CPRE447 CPRE452 Pretty patches 152 0.000584 ch2 Dell7440 0.04593 2023-06-29 2024-08-16 good/good 37 30 320.481 0.1871609 0.9814

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  8  9 10 11 12 13 14 15 18 19 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 1.35
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  6  7  8 10 14 15 18 19 32 33 34 35 37 38 70 71
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.96 1.12
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     412.6118 -0.05312229 0.9871950      NA   164    224
##   2:    NA     2     411.6109 -0.05295519 0.9869631      NA   163    223
##   3:    NA     3     411.4617 -0.05292966 0.9867901      NA   165    225
##   4:    NA     4     411.3502 -0.05291152 0.9863006      NA   162    222
##   5:    NA     5     411.1088 -0.05287204 0.9868707      NA   160    220
##  ---                                                                    
## 237:    NA   237     251.6954 -0.02613041 0.9042194      NA   126    186
## 238:    NA   238     250.7176 -0.02596441 0.9067073      NA   125    185
## 239:    NA   239     249.4532 -0.02574795 0.9109527      NA   122    182
## 240:    NA   240     249.0769 -0.02568681 0.9111366      NA   124    184
## 241:    NA   241     248.2690 -0.02554964 0.9127557      NA   123    183
##         time endtime    oxy endoxy        rate
##        <num>   <num>  <num>  <num>       <num>
##   1: 5952.35 6012.35 96.395 93.212 -0.05312229
##   2: 5951.35 6011.35 96.367 93.253 -0.05295519
##   3: 5953.35 6013.35 96.164 93.304 -0.05292966
##   4: 5950.36 6010.36 96.456 93.365 -0.05291152
##   5: 5948.35 6008.35 96.611 93.416 -0.05287204
##  ---                                          
## 237: 5914.35 5974.35 97.314 95.267 -0.02613041
## 238: 5913.35 5973.35 97.399 95.270 -0.02596441
## 239: 5910.35 5970.35 97.515 95.666 -0.02574795
## 240: 5912.35 5972.35 97.396 95.410 -0.02568681
## 241: 5911.35 5971.35 97.410 95.579 -0.02554964
## 
## Regressions : 241 | Results : 241 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 241 adjusted rate(s):
## Rate          : -0.05312229
## Adjustment    : 0.001374391
## Adjusted Rate : -0.05449668 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 41 rate(s) removed, 200 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 199 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1      rsq density row endrow    time
## 1:  NA    1     412.6118 -0.05312229 0.987195      NA 164    224 5952.35
##    endtime    oxy endoxy        rate  adjustment rate.adjusted  rate.input
## 1: 6012.35 96.395 93.212 -0.05312229 0.001374391   -0.05449668 -0.05449668
##    oxy.unit time.unit  volume     mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04593 0.000584   NA 37 30 1.013253 -0.5542691
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -949.0909          NA  mgO2/hr/kg   -949.0909
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
131 3 CPRE447 CPRE452 Pretty patches 152 0.000584 ch2 Dell7440 0.04593 2023-06-29 2024-08-16 good/good 37 30 320.481 0.1871609 0.9814 949.0909 0.5542691 0.987195 628.6099 0.3671082

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 352 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

4

Enter specimen data

Replicate = 4 
mass = 0.0005225
chamber = "ch1" 
Swim = "good/good"
chamber_vol = chamber1_dell
system1 = "Dell7440"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "29 June 2023 12 12PM/Oxygen"
experiment_mmr_date2 <- "29 June 2023 12 12PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.001905599

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell7440/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean, bg_post3$rate.bg.mean)  
bg_post 
## [1] -0.001768897

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  8  9 10 11 12 13 14 15 18 19 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 8.57
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME)
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  3  4  5  6 20 22 47 48 50 51 53 54 55 56 61 62 71 72 74 75
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.95 8.57
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=255, 
                              by="time", 
                              plot=TRUE)  
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density   row endrow     time
## 1:   2    1     252.5356 -0.02183169 0.974      NA   556    811  6990.35
## 2:  10    1     402.0431 -0.02654448 0.972      NA  4876   5131 11310.35
## 3:  15    1     468.0005 -0.02619731 0.996      NA  7542   7795 14010.80
## 4:  18    1     536.1485 -0.02784907 0.997      NA  9154   9409 15630.46
## 5:  20    1     530.4281 -0.02570043 0.997      NA 10234  10489 16710.46
## 6:  21    1     589.8320 -0.02831299 0.995      NA 10774  11029 17250.46
##     endtime     oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1:  7245.35  99.776 93.836 -0.02183169  0.0016770314   -0.02350873 -0.02350873
## 2: 11565.35 101.060 94.536 -0.02654448  0.0002415254   -0.02678600 -0.02678600
## 3: 14265.87 100.900 94.071 -0.02619731 -0.0006558270   -0.02554148 -0.02554148
## 4: 15885.46 100.590 93.637 -0.02784907 -0.0011940172   -0.02665506 -0.02665506
## 5: 16965.46 100.690 94.248 -0.02570043 -0.0015528937   -0.02414754 -0.02414754
## 6: 17505.46 100.970 94.084 -0.02831299 -0.0017323319   -0.02658066 -0.02658066
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0465 0.0005225   NA 37 30 1.013253 -0.2420673
## 2:     %Air       sec 0.0465 0.0005225   NA 37 30 1.013253 -0.2758132
## 3:     %Air       sec 0.0465 0.0005225   NA 37 30 1.013253 -0.2629984
## 4:     %Air       sec 0.0465 0.0005225   NA 37 30 1.013253 -0.2744648
## 5:     %Air       sec 0.0465 0.0005225   NA 37 30 1.013253 -0.2486451
## 6:     %Air       sec 0.0465 0.0005225   NA 37 30 1.013253 -0.2736988
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -463.2868          NA  mgO2/hr/kg   -463.2868
## 2:   -527.8721          NA  mgO2/hr/kg   -527.8721
## 3:   -503.3463          NA  mgO2/hr/kg   -503.3463
## 4:   -525.2915          NA  mgO2/hr/kg   -525.2915
## 5:   -475.8759          NA  mgO2/hr/kg   -475.8759
## 6:   -523.8254          NA  mgO2/hr/kg   -523.8254
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple")  
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
131 4 CPRE447 CPRE452 Pretty patches 152 0.0005225 ch1 Dell7440 0.0465 2023-06-29 2024-08-16 good/good 37 30 511.2422 0.2671241 0.9914

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  8  9 10 11 12 13 14 15 18 19 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.94 8.57
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  3  4  5  6 20 22 47 48 50 51 53 54 55 56 61 62 71 72 74 75
## Minimum and Maximum intervals in uneven Time data: 
## [1] 0.96 1.06
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     545.5176 -0.06889828 0.9945145      NA    76    136
##   2:    NA     2     544.5861 -0.06875517 0.9942221      NA    77    137
##   3:    NA     3     544.2733 -0.06870880 0.9940715      NA    75    135
##   4:    NA     4     542.5557 -0.06844656 0.9937161      NA    74    134
##   5:    NA     5     541.4767 -0.06827894 0.9929253      NA    78    138
##  ---                                                                    
## 236:    NA   236     378.7515 -0.04327894 0.9735820      NA     4     64
## 237:    NA   237     378.6438 -0.04326065 0.9732257      NA     1     61
## 238:    NA   238     376.6553 -0.04322536 0.9788628      NA   160    220
## 239:    NA   239     377.1276 -0.04302751 0.9738787      NA     3     63
## 240:    NA   240     375.6190 -0.04279386 0.9728781      NA     2     62
##         time endtime     oxy endoxy        rate
##        <num>   <num>   <num>  <num>       <num>
##   1: 6510.35 6570.35  96.873 92.932 -0.06889828
##   2: 6511.35 6571.35  96.856 92.949 -0.06875517
##   3: 6509.35 6569.35  96.811 92.908 -0.06870880
##   4: 6508.35 6568.35  96.920 92.984 -0.06844656
##   5: 6512.35 6572.35  97.000 93.045 -0.06827894
##  ---                                           
## 236: 6438.35 6498.35  99.996 97.366 -0.04327894
## 237: 6435.35 6495.35 100.410 97.615 -0.04326065
## 238: 6594.36 6654.36  91.750 88.956 -0.04322536
## 239: 6437.35 6497.35 100.140 97.425 -0.04302751
## 240: 6436.36 6496.36 100.360 97.555 -0.04279386
## 
## Regressions : 240 | Results : 240 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 240 adjusted rate(s):
## Rate          : -0.06889828
## Adjustment    : 0.001905599
## Adjusted Rate : -0.07080388 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 240 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 239 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     545.5176 -0.06889828 0.9945145      NA  76    136 6510.35
##    endtime    oxy endoxy        rate  adjustment rate.adjusted  rate.input
## 1: 6570.35 96.873 92.932 -0.06889828 0.001905599   -0.07080388 -0.07080388
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0465 0.0005225   NA 37 30 1.013253 -0.7290615
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1395.333          NA  mgO2/hr/kg   -1395.333
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
131 4 CPRE447 CPRE452 Pretty patches 152 0.0005225 ch1 Dell7440 0.0465 2023-06-29 2024-08-16 good/good 37 30 511.2422 0.2671241 0.9914 1395.333 0.7290615 0.9945145 884.0907 0.4619374

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 353 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

5

Enter specimen data

Replicate = 5 
mass = 0.0004876
chamber = "ch4" 
Swim = "good/good"
chamber_vol = chamber4_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "29 June 2023 12 39PM/Oxygen"
experiment_mmr_date2_asus <- "29 June 2023 12 39PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -4.04769e-05

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------
## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001209104

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.53
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8 11 12 13 14 15 16 17 19 20 21 22 24
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.45
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2_asus$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   4    1     373.2544 -0.02713877 0.966      NA 1210   1399 10106.75
## 2:   5    1     372.6508 -0.02573188 0.996      NA 1610   1799 10646.66
## 3:  16    1     550.8013 -0.02721238 0.985      NA 6013   6202 16587.63
## 4:  19    1     606.6257 -0.02786416 0.982      NA 7214   7403 18207.22
## 5:  20    1     585.0676 -0.02590524 0.976      NA 7615   7804 18747.16
## 6:  21    1     653.6279 -0.02870211 0.988      NA 8016   8206 19286.94
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1: 10362.07 98.453 91.737 -0.02713877 -0.0006036127   -0.02653516 -0.02653516
## 2: 10901.46 98.573 92.044 -0.02573188 -0.0006802688   -0.02505162 -0.02505162
## 3: 16842.88 99.402 92.534 -0.02721238 -0.0015242025   -0.02568818 -0.02568818
## 4: 18461.74 99.230 92.644 -0.02786416 -0.0017542099   -0.02610995 -0.02610995
## 5: 19001.66 99.270 93.361 -0.02590524 -0.0018309057   -0.02407433 -0.02407433
## 6: 19542.74 99.386 92.259 -0.02870211 -0.0019076726   -0.02679444 -0.02679444
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04791 0.0004876   NA 37 30 1.013253 -0.2815153
## 2:     %Air       sec 0.04791 0.0004876   NA 37 30 1.013253 -0.2657762
## 3:     %Air       sec 0.04791 0.0004876   NA 37 30 1.013253 -0.2725296
## 4:     %Air       sec 0.04791 0.0004876   NA 37 30 1.013253 -0.2770042
## 5:     %Air       sec 0.04791 0.0004876   NA 37 30 1.013253 -0.2554081
## 6:     %Air       sec 0.04791 0.0004876   NA 37 30 1.013253 -0.2842661
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -577.3488          NA  mgO2/hr/kg   -577.3488
## 2:   -545.0701          NA  mgO2/hr/kg   -545.0701
## 3:   -558.9204          NA  mgO2/hr/kg   -558.9204
## 4:   -568.0971          NA  mgO2/hr/kg   -568.0971
## 5:   -523.8065          NA  mgO2/hr/kg   -523.8065
## 6:   -582.9903          NA  mgO2/hr/kg   -582.9903
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
131 5 CPRE447 CPRE452 Pretty patches 152 0.0004876 ch4 Asus 0.04791 2023-06-29 2024-08-16 good/good 37 30 566.4853 0.2762182 0.9834

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.53
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  5  6  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.48
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0    slope_b1       rsq density   row endrow
##      <num> <int>        <num>       <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     476.6133 -0.05565147 0.9941830      NA   130    175
##   2:    NA     2     476.0388 -0.05556965 0.9939172      NA   129    174
##   3:    NA     3     475.9995 -0.05556231 0.9939368      NA   131    176
##   4:    NA     4     475.0024 -0.05541798 0.9935483      NA   132    177
##   5:    NA     5     474.7668 -0.05538715 0.9934211      NA   128    173
##  ---                                                                    
## 174:    NA   174     248.4842 -0.02236388 0.8702473      NA    19     64
## 175:    NA   175     246.1340 -0.02201407 0.8658444      NA    15     60
## 176:    NA   176     245.9754 -0.02199410 0.8690167      NA    18     63
## 177:    NA   177     244.4880 -0.02177321 0.8693261      NA    16     61
## 178:    NA   178     244.4664 -0.02177119 0.8692902      NA    17     62
##         time endtime    oxy endoxy        rate
##        <num>   <num>  <num>  <num>       <num>
##   1: 6913.05 6973.05 91.760 88.676 -0.05565147
##   2: 6911.70 6971.70 91.828 88.700 -0.05556965
##   3: 6914.44 6974.44 91.751 88.622 -0.05556231
##   4: 6915.81 6975.81 91.694 88.563 -0.05541798
##   5: 6910.37 6970.37 91.859 88.764 -0.05538715
##  ---                                          
## 174: 6763.23 6823.23 97.227 95.746 -0.02236388
## 175: 6757.80 6817.80 97.814 95.841 -0.02201407
## 176: 6761.91 6821.91 97.329 95.778 -0.02199410
## 177: 6759.21 6819.21 97.644 95.823 -0.02177321
## 178: 6760.56 6820.56 97.479 95.802 -0.02177119
## 
## Regressions : 178 | Results : 178 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 178 adjusted rate(s):
## Rate          : -0.05565147
## Adjustment    : -4.04769e-05
## Adjusted Rate : -0.05561099 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 26 rate(s) removed, 152 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 151 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1      rsq density row endrow    time
## 1:  NA    1     476.6133 -0.05565147 0.994183      NA 130    175 6913.05
##    endtime   oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 6973.05 91.76 88.676 -0.05565147 -4.04769e-05   -0.05561099 -0.05561099
##    oxy.unit time.unit  volume      mass area  S  t        P  rate.abs
## 1:     %Air       sec 0.04791 0.0004876   NA 37 30 1.013253 -0.589985
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1209.977          NA  mgO2/hr/kg   -1209.977
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
131 5 CPRE447 CPRE452 Pretty patches 152 0.0004876 ch4 Asus 0.04791 2023-06-29 2024-08-16 good/good 37 30 566.4853 0.2762182 0.9834 1209.977 0.589985 0.994183 643.4921 0.3137667
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 354 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

7

Enter specimen data

Replicate = 7 
mass = 0.0003497 
chamber = "ch2" 
Swim = "good/good"
chamber_vol = chamber2_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "29 June 2023 12 59PM/Oxygen"
experiment_mmr_date2_asus <- "29 June 2023 12 59PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.0003542458

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean) #,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.0019847

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.53
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8 11 12 13 14 15 16 17 19 20 21 22 24
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.45
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   4    1     250.5303 -0.01490335 0.989      NA 1210   1391 10106.75
## 2:  12    1     305.3666 -0.01428902 0.991      NA 4413   4594 14426.94
## 3:  14    1     354.0189 -0.01640282 0.991      NA 5212   5394 15506.42
## 4:  16    1     370.1599 -0.01631520 0.993      NA 6013   6194 16587.63
## 5:  18    1     372.1422 -0.01542905 0.992      NA 6813   6995 17667.16
## 6:  20    1     414.8873 -0.01683325 0.995      NA 7615   7797 18747.16
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 10351.23 99.654 96.337 -0.01490335 -0.001138851   -0.01376450 -0.01376450
## 2: 14671.86 99.289 95.385 -0.01428902 -0.001995085   -0.01229393 -0.01229393
## 3: 15752.18 99.562 95.480 -0.01640282 -0.002209103   -0.01419372 -0.01419372
## 4: 16832.08 99.511 95.749 -0.01631520 -0.002423251   -0.01389195 -0.01389195
## 5: 17912.37 99.469 95.569 -0.01542905 -0.002637271   -0.01279178 -0.01279178
## 6: 18992.22 99.254 95.040 -0.01683325 -0.002851294   -0.01398195 -0.01398195
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04573 0.0003497   NA 37 30 1.013253 -0.1393849
## 2:     %Air       sec 0.04573 0.0003497   NA 37 30 1.013253 -0.1244933
## 3:     %Air       sec 0.04573 0.0003497   NA 37 30 1.013253 -0.1437314
## 4:     %Air       sec 0.04573 0.0003497   NA 37 30 1.013253 -0.1406755
## 5:     %Air       sec 0.04573 0.0003497   NA 37 30 1.013253 -0.1295347
## 6:     %Air       sec 0.04573 0.0003497   NA 37 30 1.013253 -0.1415869
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -398.5841          NA  mgO2/hr/kg   -398.5841
## 2:   -356.0004          NA  mgO2/hr/kg   -356.0004
## 3:   -411.0134          NA  mgO2/hr/kg   -411.0134
## 4:   -402.2749          NA  mgO2/hr/kg   -402.2749
## 5:   -370.4168          NA  mgO2/hr/kg   -370.4168
## 6:   -404.8811          NA  mgO2/hr/kg   -404.8811
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
131 7 CPRE447 CPRE452 Pretty patches 152 0.0003497 ch2 Asus 0.04573 2023-06-29 2024-08-16 good/good 37 30 397.4341 0.1389827 0.992

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.53
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row,
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  3  4  5  6  7  8 11 12 13 14 15 16 17 18 19 20 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.41
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0     slope_b1       rsq density   row endrow
##      <num> <int>        <num>        <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     398.9111 -0.037708554 0.9921018      NA    55    100
##   2:    NA     2     398.3712 -0.037641607 0.9918503      NA    54     99
##   3:    NA     3     398.0386 -0.037599255 0.9916361      NA    56    101
##   4:    NA     4     396.9570 -0.037465640 0.9910418      NA    53     98
##   5:    NA     5     396.7796 -0.037441867 0.9910798      NA    57    102
##  ---                                                                     
## 174:    NA   174     150.2084 -0.007010519 0.7864835      NA   174    219
## 175:    NA   175     145.0502 -0.006379905 0.7656599      NA   175    220
## 176:    NA   176     141.3112 -0.005922835 0.7430687      NA   176    221
## 177:    NA   177     138.4048 -0.005567575 0.7191215      NA   177    222
## 178:    NA   178     135.4639 -0.005208139 0.6915239      NA   178    223
##         time endtime    oxy endoxy         rate
##        <num>   <num>  <num>  <num>        <num>
##   1: 7986.25 8046.25 97.698 95.556 -0.037708554
##   2: 7984.92 8044.92 97.699 95.598 -0.037641607
##   3: 7987.64 8047.64 97.679 95.559 -0.037599255
##   4: 7983.58 8043.58 97.708 95.634 -0.037465640
##   5: 7989.01 8049.01 97.655 95.509 -0.037441867
##  ---                                           
## 174: 8147.19 8207.19 93.302 92.796 -0.007010519
## 175: 8148.54 8208.54 93.244 92.794 -0.006379905
## 176: 8149.91 8209.91 93.168 92.772 -0.005922835
## 177: 8151.26 8211.26 93.114 92.763 -0.005567575
## 178: 8152.60 8212.60 93.096 92.768 -0.005208139
## 
## Regressions : 178 | Results : 178 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 178 adjusted rate(s):
## Rate          : -0.03770855
## Adjustment    : -0.0003542458
## Adjusted Rate : -0.03735431 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 17 rate(s) removed, 161 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 160 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     398.9111 -0.03770855 0.9921018      NA  55    100 7986.25
##    endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1: 8046.25 97.698 95.556 -0.03770855 -0.0003542458   -0.03735431 -0.03735431
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04573 0.0003497   NA 37 30 1.013253 -0.3782649
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1081.684          NA  mgO2/hr/kg   -1081.684
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
131 7 CPRE447 CPRE452 Pretty patches 152 0.0003497 ch2 Asus 0.04573 2023-06-29 2024-08-16 good/good 37 30 397.4341 0.1389827 0.992 1081.684 0.3782649 0.9921018 684.2499 0.2392822
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 355 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

8

Enter specimen data

Replicate = 8 
mass = 0.0004363 
chamber = "ch1" 
Swim = "good/good"
chamber_vol = chamber1_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "29 June 2023 01 08PM/Oxygen"
experiment_mmr_date2_asus <- "29 June 2023 01 08PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.0001158766

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.0020101

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.53
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8 11 12 13 14 15 16 17 19 20 21 22 24
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.45
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=15, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 1 rate(s) removed, 20 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 14 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   9    1     298.1241 -0.01546779 0.996      NA 3212   3394 12807.22
## 2:  10    1     298.6105 -0.01490689 0.953      NA 3612   3794 13346.69
## 3:  12    1     301.0500 -0.01396336 0.991      NA 4413   4594 14426.94
## 4:  15    1     353.4306 -0.01582176 0.970      NA 5613   5795 16047.69
## 5:  17    1     368.9603 -0.01573558 0.984      NA 6412   6594 17126.47
## 6:  19    1     389.9165 -0.01596449 0.991      NA 7214   7396 18207.22
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 13052.57 99.934 96.237 -0.01546779 -0.001649283   -0.01381851 -0.01381851
## 2: 13592.24 99.838 96.307 -0.01490689 -0.001773516   -0.01313338 -0.01313338
## 3: 14671.86 99.461 96.292 -0.01396336 -0.002022165   -0.01194120 -0.01194120
## 4: 16293.21 99.857 95.116 -0.01582176 -0.002395403   -0.01342636 -0.01342636
## 5: 17371.82 99.545 95.752 -0.01573558 -0.002643767   -0.01309181 -0.01309181
## 6: 18452.26 99.277 95.534 -0.01596449 -0.002892569   -0.01307193 -0.01307193
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04565 0.0004363   NA 37 30 1.013253 -0.1396870
## 2:     %Air       sec 0.04565 0.0004363   NA 37 30 1.013253 -0.1327613
## 3:     %Air       sec 0.04565 0.0004363   NA 37 30 1.013253 -0.1207099
## 4:     %Air       sec 0.04565 0.0004363   NA 37 30 1.013253 -0.1357229
## 5:     %Air       sec 0.04565 0.0004363   NA 37 30 1.013253 -0.1323411
## 6:     %Air       sec 0.04565 0.0004363   NA 37 30 1.013253 -0.1321401
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -320.1628          NA  mgO2/hr/kg   -320.1628
## 2:   -304.2889          NA  mgO2/hr/kg   -304.2889
## 3:   -276.6671          NA  mgO2/hr/kg   -276.6671
## 4:   -311.0771          NA  mgO2/hr/kg   -311.0771
## 5:   -303.3259          NA  mgO2/hr/kg   -303.3259
## 6:   -302.8651          NA  mgO2/hr/kg   -302.8651
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
131 8 CPRE447 CPRE452 Pretty patches 152 0.0004363 ch1 Asus 0.04565 2023-06-29 2024-08-16 good/good 37 30 308.344 0.1345305 0.9788

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.53
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row,  
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  4  5  6  7  8  9 10 11 12 13 14 16 17 18 19 20 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.32 1.44
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##        rep  rank intercept_b0     slope_b1       rsq density   row endrow
##      <num> <int>        <num>        <num>     <num>  <lgcl> <int>  <int>
##   1:    NA     1     772.4076 -0.077997105 0.9735665      NA   163    208
##   2:    NA     2     770.4239 -0.077767173 0.9722382      NA   164    209
##   3:    NA     3     770.0767 -0.077732179 0.9721510      NA   162    207
##   4:    NA     4     766.3028 -0.077292522 0.9696738      NA   165    210
##   5:    NA     5     762.4786 -0.076863451 0.9669744      NA   161    206
##  ---                                                                     
## 173:    NA   173     127.9761 -0.003629088 0.1672702      NA    37     82
## 174:    NA   174     127.8752 -0.003619856 0.1743150      NA    41     86
## 175:    NA   175     125.3957 -0.003328179 0.1504622      NA    38     83
## 176:    NA   176     124.2384 -0.003194618 0.1435938      NA    40     85
## 177:    NA   177     123.8118 -0.003143937 0.1407204      NA    39     84
##         time endtime    oxy endoxy         rate
##        <num>   <num>  <num>  <num>        <num>
##   1: 8692.27 8752.27 93.974 90.145 -0.077997105
##   2: 8693.61 8753.61 93.963 90.214 -0.077767173
##   3: 8690.91 8750.91 93.856 90.157 -0.077732179
##   4: 8694.95 8754.95 93.968 90.154 -0.077292522
##   5: 8689.54 8749.54 93.850 90.167 -0.076863451
##  ---                                           
## 173: 8521.82 8581.82 97.198 96.821 -0.003629088
## 174: 8527.21 8587.21 96.951 96.658 -0.003619856
## 175: 8523.20 8583.20 97.261 96.745 -0.003328179
## 176: 8525.88 8585.88 97.152 96.646 -0.003194618
## 177: 8524.54 8584.54 97.242 96.687 -0.003143937
## 
## Regressions : 177 | Results : 177 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 177 adjusted rate(s):
## Rate          : -0.07799711
## Adjustment    : -0.0001158766
## Adjusted Rate : -0.07788123 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 118 rate(s) removed, 59 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 58 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     772.4076 -0.07799711 0.9735665      NA 163    208 8692.27
##    endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1: 8752.27 93.974 90.145 -0.07799711 -0.0001158766   -0.07788123 -0.07788123
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04565 0.0004363   NA 37 30 1.013253 -0.7872773
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:    -1804.44          NA  mgO2/hr/kg    -1804.44
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
131 8 CPRE447 CPRE452 Pretty patches 152 0.0004363 ch1 Asus 0.04565 2023-06-29 2024-08-16 good/good 37 30 308.344 0.1345305 0.9788 1804.44 0.7872773 0.9735665 1496.096 0.6527468
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 356 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)